const LocalEvent = require('../class/LocalEvent');

let Debug = false;

/** 玩家登录事件 */
WSC.addApiEventName(CONSTANTS.EVENT.PLAYER_LOGIN);
WSC.get(CONSTANTS.EVENT.PLAYER_LOGIN, async (wscclient, req, res)=>{
    const jsonExample = {
        body: {
            data: {
                loginTime: 123123123,
                xuid: "",
                uuid: "",
                realName: ""
            }
        }
    };
    let eventJson = new LocalEvent()
        .setSourceId(req.header.source_id)
        .setSourceBdsUuid(req.header.source_bds_uuid)
        .setSourceBdsServerName(req.header.source_bds_serverName)
        .setData(req.body.data).json;
    WSC.api.listener.emit(CONSTANTS.EVENT.PLAYER_LOGIN, eventJson);
    Debug && console.log("[Event]玩家登录事件: ", eventJson);
});


/** 玩家登出事件 */
WSC.addApiEventName(CONSTANTS.EVENT.PLAYER_LOGOUT);
WSC.get(CONSTANTS.EVENT.PLAYER_LOGOUT, async (wscclient, req, res)=>{
    const jsonExample = {
        body: {
            data: {
                loginTime: 123123123,
                xuid: "",
                uuid: "",
                realName: ""
            }
        }
    };
    let eventJson = new LocalEvent()
        .setSourceId(req.header.source_id)
        .setSourceBdsUuid(req.header.source_bds_uuid)
        .setSourceBdsServerName(req.header.source_bds_serverName)
        .setData(req.body.data).json;
    WSC.api.listener.emit(CONSTANTS.EVENT.PLAYER_LOGOUT, eventJson);
    Debug && console.log("[Event]玩家登出事件: ", eventJson);
}); 



/** 玩家聊天事件 */
WSC.addApiEventName(CONSTANTS.EVENT.PLAYER_CHAT);
WSC.api.listener.on(CONSTANTS.EVENT.PLAYER_CHAT, (json)=>{
    Debug && console.log("[Event]玩家聊天事件: ", json);
});
WSC.get(CONSTANTS.EVENT.PLAYER_CHAT, async (wscclient, req, res)=>{
    const jsonExample = {
        body: {
            mesasge: '你好',
            receiver: "",
            sender: 'Wn1027',
            type: 'chat',
            time: 123123123,
        }
    };
});


/** 玩家登录同步成功事件 */
WSC.addApiEventName(CONSTANTS.EVENT.PLAYER_LOGIN_SYNC_SUCCESS);
WSC.get(CONSTANTS.EVENT.PLAYER_LOGIN_SYNC_SUCCESS, async (wscclient, req, res)=>{
    const jsonExample = {
        body: {
            data: {
                xuid: "",
                uuid: "",
                realName: ""
            }
        }
    };
    let eventJson = new LocalEvent()
        .setSourceId(req.header.source_id)
        .setSourceBdsUuid(req.header.source_bds_uuid)
        .setSourceBdsServerName(req.header.source_bds_serverName)
        .setData(req.body.data).json;
    WSC.api.listener.emit(CONSTANTS.EVENT.PLAYER_LOGIN_SYNC_SUCCESS, eventJson);
    Debug && console.log("[Event]玩家登录同步成功事件: ", eventJson);
});


/** 客户端连接事件 */
WSC.addApiEventName(CONSTANTS.EVENT.CLIENT_CONNECT);
WSC.get(CONSTANTS.EVENT.CLIENT_CONNECT, async (wscclient, req, res)=>{
    const jsonExample = {
       // 参考co_server/ClientManager类属性
    };
    let eventJson = new LocalEvent()
        .setSourceId(req.header.source_id)
        .setSourceBdsUuid(req.header.source_bds_uuid)
        .setSourceBdsServerName(req.header.source_bds_serverName)
        .setData(req.body.data).json;
    WSC.api.listener.emit(CONSTANTS.EVENT.CLIENT_CONNECT, eventJson);
    Debug && console.log("[Event]客户端连接事件: ", eventJson);
}); 


/** 客户端断开事件 */
WSC.addApiEventName(CONSTANTS.EVENT.CLIENT_CLOSE);
WSC.get(CONSTANTS.EVENT.CLIENT_CLOSE, async (wscclient, req, res)=>{
    const jsonExample = {
    // 参考co_server/ClientManager类属性
    };
    let eventJson = new LocalEvent()
        .setSourceId(req.header.source_id)
        .setSourceBdsUuid(req.header.source_bds_uuid)
        .setSourceBdsServerName(req.header.source_bds_serverName)
        .setData(req.body.data).json;
    WSC.api.listener.emit(CONSTANTS.EVENT.CLIENT_CLOSE, eventJson);
    Debug && console.log("[Event]客户端断开事件: ", eventJson);
}); 







